refactor(tooling): replace SQLite skill tracking with CSV log and Cursor slash-command hook#29139
refactor(tooling): replace SQLite skill tracking with CSV log and Cursor slash-command hook#29139NicolasMassart wants to merge 21 commits into
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
|
✅ E2E Fixture Validation — Schema is up to date |
…oach Rewrites the AI tool usage collection system to use a local CSV append log instead of a direct SQLite write from hooks. Hooks are now pure-shell (no Node/yarn/tsx dependency), with the DB populated on-demand by the dev-tooling-explorer or nightly cron. Splits the shared dispatcher into agent-specific entry scripts (hook-cursor-dispatch.sh, hook-claude-dispatch.sh) and a common script (hook-common.sh). Removes obsolete Node modules (db.ts, events.ts, tool-usage-collection.ts, cursor-hook-skill-tracking.ts) and the better-sqlite3 dependency. Adds full test coverage for both the shell dispatcher and the Yarn plugin. Co-authored-by: Cursor <cursoragent@cursor.com>
18aeef3 to
300187f
Compare
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
None of these changes touch: app components, controllers, navigation, Engine, test fixtures, E2E test page objects, or any code path exercised by Detox E2E tests. No E2E tags are warranted. Performance Test Selection: |
…ollowup # Conflicts: # package.json
Changed the error type from `NodeJS.ErrnoError` to `NodeJS.ErrnoException` in the `runDispatcher` function to ensure proper error handling in the test suite.
…prompts - Introduced a new `beforeSubmitPrompt` hook in `.cursor/hooks.json` that triggers the `hook-cursor-prompt-dispatch.sh` script. - The new script processes user prompts, extracts skill names from slash commands, and logs relevant data while ensuring prompt submissions are never blocked. - Updated `hook-common.sh` to improve payload handling. - Added comprehensive tests for the new functionality in `hook-dispatchers.test.ts`. - Updated documentation in `README.md` to reflect the new hook and its purpose.
… github.com:MetaMask/metamask-mobile into MCWP-513-po-c-phase-2-automated-collection-followup
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #29139 +/- ##
===========================================
- Coverage 81.54% 43.21% -38.34%
===========================================
Files 5343 5358 +15
Lines 142128 142541 +413
Branches 32411 32527 +116
===========================================
- Hits 115899 61595 -54304
- Misses 18299 75110 +56811
+ Partials 7930 5836 -2094 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Changed the execution method from `.` to `sh` for sourcing `hook-common.sh` in both `hook-claude-dispatch.sh` and `hook-cursor-dispatch.sh` scripts to ensure proper script execution.
… github.com:MetaMask/metamask-mobile into MCWP-513-po-c-phase-2-automated-collection-followup
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fc9674fe4a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Introduced a guard to log only known skills by checking for the existence of SKILL.md files in predefined directories. - This prevents misclassification of built-in Cursor commands as skill invocations, enhancing the accuracy of skill handling in the script.
… github.com:MetaMask/metamask-mobile into MCWP-513-po-c-phase-2-automated-collection-followup
- Added a `beforeEach` hook to create a temporary skills directory and a stub `SKILL.md` file for testing slash command invocations. - Updated environment variables in test cases to ensure proper resolution of the temporary directory for skill commands. - This change improves the accuracy of tests related to slash command handling in the dispatcher.
- Updated the plugin usage tracking to clarify that only Yarn scripts defined in package.json are logged, addressing a Yarn Berry limitation. - Improved the skill name validation in hook-cursor-prompt-dispatch.sh to allow for underscores in skill names, ensuring better compatibility with various naming conventions. - Refactored log file creation to prevent duplicate header rows when multiple scripts run concurrently, enhancing the reliability of the logging mechanism. - Updated tests to ensure correct logging behavior for known and unknown skills, improving overall test coverage and accuracy.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5126c91. Configure here.
… update test environment variables - Updated the skill logging guard in `hook-cursor-prompt-dispatch.sh` to allow overriding the repository root for testing purposes. - Modified test cases in `hook-dispatchers.test.ts` to use the new `TOOL_USAGE_REPO_ROOT` environment variable instead of `GIT_DIR`, improving test isolation and flexibility.
|




Description
Follow-up to #28815 (Phase 2 automated collection).
Rewrites the AI tool usage collection system to use a local CSV append log instead of direct SQLite writes from hooks. The root cause driving the change: the hook shell environment does not honour
.nvmrc, so hooks were running against the system Node rather than the project's pinned version — makingbetter-sqlite3bindings unreliable. The fix decouples write-time from read-time: hooks now do a pure-shellprintf >> file(zero Node dependency), and the SQLite DB will be populated on-demand by dev-tooling-explorer or the future cron.What changed:
~/.tool-usage-collection/metamask-mobile-events.log. The SQLite DB is populated on-demand bydev-tooling-exploreror the nightly cron — not by the hooks themselves.hook-cursor-dispatch.sh,hook-claude-dispatch.sh) and a sharedhook-common.sh. No Node, no yarn, no subprocess spawning in the hook path.hook-cursor-dispatch.shunconditionally emits{"permission":"allow"}as its first line (before any CI/opt-out check) so tool use is never blocked regardless of tracking state.hook-cursor-prompt-dispatch.shon thebeforeSubmitPromptevent. When a user invokes a skill via a slash command (e.g./mms-pr-changelog), Cursor injects the skill content directly into the prompt context without the agent reading a SKILL.md file — so the existingpreToolUsepath never fires. This hook intercepts the raw prompt, extracts the skill name, and appends one CSV row. The{"permission":"allow"}response is always emitted first.hook-common.shandhook-cursor-prompt-dispatch.sh— no unnecessarycaton opted-out runs.ReadFile/Read) — preventsStrReplaceand other tools carrying skill paths as string content from generating spurious log entries..claude/settings.json: Project-levelPreToolUsehook on theSkilltool (replaces per-skill frontmatter hooks). Zero per-skill boilerplate.db.ts,events.ts,tool-usage-collection.ts,cursor-hook-skill-tracking.ts,better-sqlite3dependency,@types/better-sqlite3.child_process.execFileSync) and the Yarn plugin's CSV append path. Test file renamed fromhook-skill-tracking-dispatch.test.tstohook-dispatchers.test.tsto match the actual scripts.scripts/tooling/README.mdwith new architecture diagram (all 4 collection paths) andAGENTS.mdcollection-path table.Changelog
CHANGELOG entry: null
Related issues
Refs: MCWP-513
Manual testing steps
Screenshots/Recordings
Before
N/A
After
Log file should look like the following:
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Medium Risk
Touches developer workflow hooks for Yarn/Claude/Cursor; a bug could silently stop tracking or (for Cursor) potentially interfere with tool/prompt flow despite safeguards to always emit allow.
Overview
Replaces SQLite-based tool/skill usage tracking with a local append-only CSV log (
~/.tool-usage-collection/metamask-mobile-events.log) and removes the Node/SQLite CLI +better-sqlite3dependency.Updates hook wiring to use pure-shell dispatchers: adds
.claude/settings.jsonprojectPreToolUsehook, changes Cursor topreToolUse+ newbeforeSubmitPrompthook for slash-command skills, and adds sharedhook-common.shto extract skill names/session ids and append CSV with a one-time header.Refactors the Yarn Berry plugin to write CSV rows directly (start/end/interrupted with duration/success) and adds Jest coverage for the plugin and new shell dispatchers; updates docs/config (
AGENTS.md,scripts/tooling/README.md,babel.config.tests.js,.gitignore) accordingly.Reviewed by Cursor Bugbot for commit 3b1e8d1. Bugbot is set up for automated code reviews on this repo. Configure here.